package com.fjwt.gz.mch.ctrl.lite.homepage;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.LiteHomepageDTO;
import com.fjwt.gz.db.entity.LiteHomepageEntity;
import com.fjwt.gz.db.vo.LiteHomepageVO;
import com.fjwt.gz.mch.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.LiteHomepageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

/**
 * 首页接口类
 */
@Slf4j
@RestController
@RequestMapping("/api/liteHomePage")
public class LiteHomePageController extends CommonCtrl {

    @Autowired
    private LiteHomepageService homepageService;

    /**
     * 首页配置列表
     */
    @GetMapping
    public ApiRes getLiteHomepage() {
        Map map = getObject(Map.class);
        log.info("C端首页配置列表，请求地址：/api/liteHomePage，请求参数：{}", JSONUtil.toJsonStr(map));
        IPage<LiteHomepageEntity> page = homepageService.selectLiteHomepageList(getIPage(), map);
        log.info("C端首页配置列表，请求地址：/api/liteHomePage，返回结果：{}", JSONUtil.toJsonStr(page));
        return ApiRes.page(page);
    }

    /**
     * 获取首页配置详情
     */
    @PostMapping("/getInfo")
    public ApiRes liteHomepageGetInfo() {
        LiteHomepageDTO dto = getObject(LiteHomepageDTO.class);
        log.info("C端首页配置详情，请求地址：/api/liteHomePage/getInfo，请求参数：{}", JSONUtil.toJsonStr(dto));
        LiteHomepageVO vo = homepageService.getInfoById(dto);
        log.info("C端首页配置详情，请求地址：/api/liteHomePage/getInfo，返回结果：{}", JSONUtil.toJsonStr(vo));
        return ApiRes.ok(vo);
    }
}
